home *** CD-ROM | disk | FTP | other *** search
- Path: newsjunkie.ans.net!lexis-nexis!echo!kentb
- From: kentb@meaddata.com (Kent Bruton)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ and lex?
- Date: 22 Jan 1996 17:17:20 GMT
- Organization: LEXIS-NEXIS, Dayton OH
- Message-ID: <4e0gr0$1c9@meaddata.lexis-nexis.com>
- References: <4dugkp$fl8@apakabar.cc.columbia.edu>
- NNTP-Posting-Host: echo.lexis-nexis.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Paul E Gunnells (peg14@aloha.cc.columbia.edu) wrote:
- > Hello everyone:
-
- > Has anyone ever tried using lex along with iostream.h to handle input?
- > Or better yet, is there some equivalent to lex that works well with
- > C++?
-
- > Of course, one solution is to have an extern C function yylex() that
- > just returns tokens that your C++ program deals with, but a better
- > solution (at least a cleaner solution) would be a version of lex that
- > allows you to directly incorporate C++ code (streams, constructors)
- > into the lex source.
-
- > Is there such a beast?
-
- I'm currently in the process of reading up on a creature called
- flex 2.5. There's a section in the man page on generating C++
- scanners. I'm not yet to the point of having tried it but
- here's a snip:
-
- GENERATING C++ SCANNERS
-
- The (experimental) facility for generating C++ scanner classes.
-
- flex provides two different ways to generate scanners for
- use with C++. The first way is to simply compile a scanner
- generated by flex using a C++ compiler instead of a C com-
- piler. You should not encounter any compilations errors
- (please report any you find to the email address given in
- the Author section below). You can then use C++ code in
- your rule actions instead of C code. Note that the default
- input source for your scanner remains yyin, and default
- echoing is still done to yyout. Both of these remain FILE *
- variables and not C++ streams.
-
- You can also use flex to generate a C++ scanner class, using
- the - + option (or, equivalently, %option c++), which is
- automatically specified if the name of the flex executable
- ends in a '+', such as flex++.
-
- ...
-
- The first class, FlexLexer, provides an abstract base class
- defining the general scanner class interface.
-
- ...
-
- The second class defined in FlexLexer.h is yyFlexLexer,
- which is derived from FlexLexer. It defines the following
- additional member functions:
-
- yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
- constructs a yyFlexLexer object using the given streams
- for input and output. If not specified, the streams
- default to cin and cout, respectively.
-
- ...
-
- We'll see.
-
- Kent
-
-
-